package com.itheima.demo03;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class ObjectStreams {
    public static void main(String[] args) throws IOException {
        //序列化流  同时写入、读取多个对象数据
        //利用集合实现

        Student stu1 = new Student("张三",20,"北京");
        Student stu2 = new Student("李四",21,"上海");
        Student stu3 = new Student("王五",20,"天津");

        ArrayList<Student> list = new ArrayList<>();
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        //创建序列化输入流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("bb.txt"));
        oos.writeObject(list);

        //关闭流
        oos.close();
    }
}
